package com.aspose.word;

import com.aspose.AsposeLicese;
import com.aspose.words.MailMerge;

/**
 * Created by wangg on 2017/12/29.
 */
public class MailMergeDataSource extends AsposeLicese {
    private static com.aspose.words.License license = null;


    private boolean getLicense() {
        boolean result = true;
        try {
            if (license == null) {
                license = new com.aspose.words.License();
                license.setLicense(getLiceseIn());
            }
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public void load() throws Exception {
        if (!getLicense()) {
            return;
        }
        com.aspose.words.Document doc = new com.aspose.words.Document("F://Microsoft.docx");
        MailMerge merge = doc.getMailMerge();
        merge.execute(new String[]{"name", "carnum", "code", "num"}, new String[]{"wangg", "苏E88888", "2017", "J0001"}); //执行word域替换 name，value
        String[] names = merge.getFieldNames();
        System.out.println(names);
        doc.save("F://Microsoft2.docx");
    }

}
